package com.wnxy.jdk8;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;

public class App1 {
    public static void main(String[] args) {
        t4();
    }

    //4、函数式接口
    private static void t4(){
//        Function<String,Integer> function = new Function<String, Integer>() {
//            @Override
//            public Integer apply(String str) {
//                return Integer.parseInt(str);
//            }
//        };

        Function<String,Integer> function = (str)-> Integer.parseInt(str);
        Integer apply = function.apply("123");
        System.out.println("apply = " + apply);
    }

    //3、供给型接口Supplier：操作数据，返回T类型的结果
    private static void t3(){
        Supplier<Integer> supplier = () -> 100;
        Integer num = supplier.get();
        System.out.println("num = " + num);
    }

    //2、Predicate 断言接口
    private static void t2() {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,23,29,100,2,122);
        list.removeIf(num -> num > 30);
        list.forEach(System.out::println);
    }

    //1、Consumer消费型接口
    private static void t1() {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,23,29,100,2,122);
        list.forEach(x -> System.out.println(x));
    }
}



















